function fmtGender(value) {
    return value==1?"男":"女";
}
function fmtRole(value) {
    return value.roleName;
}

function queryUser() {
    var formParams=$("#queryForm").serialize();
    var obj=Qs.parse(formParams);
    $("#userTb").bootstrapTable("refresh",{query:obj})
}

 // function queryParams(params){
 //     var formParams=$("#queryForm").serialize();
 //     var query=Qs.parse(formParams);
 //     Object.assign(params,query);
 //     return params;
 // }


$.get("sys/role/list")
    .done(list=>{
        list.forEach(function(role){
            var opt=$("<option/>");
            opt.val(role.id);
            opt.text(role.roleName);
            opt.appendTo("#queryForm [name=roleId]");
        });
    });

function actionFormatter() {
    var ycTool=$("#ycTool").html();
    return ycTool;
}

var actionEvens={
    "click .edit":function (event,value,row) {
            console.log(row)
    }
}

function detailFormatter(index, row) {
    let html = `<table class="table table-bordered">
                    <tr>
                    <td>联系人姓名</td>
                    <td>联系人电话</td>
                    <td>联系地址</td>
                    </tr>
`;
    $(row.addressList).each(function () {
        html += `<tr>
                <td>${this.contact}</td>
                <td>${this.tel}</td>
                <td>${this.addressDesc}</td>
            </tr>`
    });
    html += `</table>`
    return html;
}

$("#grant").dialog({
        title:"用户授权",
        btnBind(){
            var arr1=$("#userTb").bootstrapTable("getSelections");
            var arr2=$("#grant table").bootstrapTable("getSelections");
            var params=`userId=${arr1[0].id}&roleId=${arr2[0].id}`;
            $.post('sys/user/grant',params)
                .done(msg=>{
                    $("#userTb").bootstrapTable("refresh")
                    $("#grant").dialog("hide");
                    toastr.success(msg);
                })

}
});
function grant() {
    var arr=$("#userTb").bootstrapTable("getSelections");
    if(arr.length!=1){
        swal("信息提示！","请至少选择一项待授权！");
        return;
    }
    $("#grant table").bootstrapTable("checkBy",{field:"id",values:[arr[0].userRole]})
    $("#grant").dialog("show");
}